package com.klaus.ohMySpace.service.Impl;

import com.klaus.ohMySpace.dao.BaseDao;
import com.klaus.ohMySpace.dao.NoteDao;
import com.klaus.ohMySpace.entity.BasicEntity;
import com.klaus.ohMySpace.entity.Note;
import com.klaus.ohMySpace.service.NoteService;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by Mklaus on 15/8/7.
 */
@Service
public class NoteServiceImpl extends BaseServiceImpl<Note> implements NoteService {
    @Resource
    private NoteDao noteDao;

    @Override
    public BaseDao getBaseDao() {
        return this.noteDao;
    }

    @Override
    public List<Note> getNotesByUserId(int userId) {
        return getNotesByUserId(userId,null,null);
    }

    @Override
    public List<Note> getNotesByUserId(int userId,Integer start,Integer size) {
        DetachedCriteria dc = DetachedCriteria.forClass(Note.class);
        dc.createCriteria("user").add(Restrictions.eq("id",userId));

        List<Note> notes = noteDao.search(dc,start,size);

        return notes;
    }
}
